package service

import (
	context3 "ksd-social-api/modules/msg/model/context"
	"ksd-social-api/modules/user/model"
)

/**
 * 用户购买会员身份
 * @author feige
 * @date 2023-11-23
 * @version 1.0
 * @desc
 */
type UserBuyVipService struct {
}

/**
 * 用户升级身份保存订单
 * @author feige
 * @date 2023-12-18
 * @version 1.0
 * @desc
 */
func (service *UserBuyVipService) SaveUserVipOrder(
	OutTradeNo string, TransactionId string, orderJson string, payMethod int, payMethodName string, price string,
	userId uint64, vipId uint64, systemId uint64, systemName string) {
	// 根据课程id查询课程信息
	userVipVo := userVipMapper.GetUserVipDetail(vipId, systemId)
	userVo := userMapper.GetUserByID(userId, systemId)

	var userBuyVip model.UserBuyVip
	userBuyVip.SystemId = systemId
	userBuyVip.SystemName = systemName
	// 处理返回结果
	userBuyVip.VipId = vipId
	userBuyVip.Title = userVipVo.Title
	userBuyVip.Description = userVipVo.Note

	userBuyVip.UserId = userId
	userBuyVip.Username = userVo.Username
	userBuyVip.Avatar = userVo.Avatar
	userBuyVip.Uuid = userVo.Uuid
	userBuyVip.Phone = userVo.Telephone
	userBuyVip.Address = userVo.Address
	userBuyVip.Nickname = userVo.Nickname

	userBuyVip.Code = ""
	userBuyVip.PayMethod = payMethod
	userBuyVip.PayMethodName = payMethodName
	userBuyVip.Tradeno = OutTradeNo
	userBuyVip.Orderno = TransactionId
	userBuyVip.OrderJson = orderJson
	userBuyVip.Price = price
	// 保存订单的接口
	userBuyVipMapper.SaveUserBuyVip(userBuyVip)
	// 修改面试简历状态
	resumeMapper.UpdateResumePayByUserId(userId, systemId)
	// 保存消息
	messageMeContext := context3.MessageMeContext{}
	messageMeContext.UserId = userId
	messageMeContext.Title = userVipVo.Title
	messageMeContext.Uuid = userVo.Uuid
	messageMeContext.SystemId = systemId
	messageMeContext.SystemName = "系统512"
	messageMeContext.Username = userVo.Nickname
	messageMeContext.Url = "https://www.study512.com"
	messageMeService.SaveMessageMeVIP(&messageMeContext)
}

/**
 * 查询用户是否购买会员身份
 * @author feige
 * @date 2023-11-23
 * @version 1.0
 * @desc
 */
func (service *UserBuyVipService) CountUserBuyVipByOutTradeNo(OutTradeNo string, systemId uint64) int {
	return userBuyVipMapper.CountUserBuyVipByOutTradeNo(OutTradeNo, systemId)
}
